package com.dyl.system.controller;


import com.dyl.common.core.utils.LayerData;
import com.dyl.common.core.utils.RestResponse;
import com.dyl.common.core.web.domain.SysLuckySheet;
import com.dyl.common.log.annotation.XudenSysLog;
import com.dyl.common.security.annotation.PreAuthorize;
import com.dyl.system.service.LuckySheetService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

//协同excel办公
@RestController
@RequestMapping("system/luckySheet")
public class LuckySheetControoler  {

    @Autowired
    private LuckySheetService luckySheetService;


    @XudenSysLog("获取办公列表数据")
    @PreAuthorize(hasPermi = "sys:luckySheet:list")
    @PostMapping("list")
    public LayerData<SysLuckySheet> list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                         @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                                         String name){
        return luckySheetService.list(page,limit,name);
    }

    @ApiOperation(value = "新增办公数据")
    @XudenSysLog("新增办公数据")
    @PreAuthorize(hasPermi = "sys:luckySheet:add")
    @PostMapping("add")
    public RestResponse add(@RequestBody SysLuckySheet sysLuckySheet){
        if(StringUtils.isBlank(sysLuckySheet.getName())){
            return RestResponse.failure("项目名称不能为空");
        }
        if(luckySheetService.saveSysLuckySheet(sysLuckySheet))return RestResponse.success();
        return RestResponse.failure("添加失败");
    }


    @ApiOperation(value = "编辑办公数据")
    @XudenSysLog("编辑办公数据")
    @PreAuthorize(hasPermi = "sys:luckySheet:update")
    @PostMapping("update")
    public RestResponse update(@RequestBody SysLuckySheet sysLuckySheet){
        if(StringUtils.isBlank(sysLuckySheet.getName())){
            return RestResponse.failure("项目名称不能为空");
        }
        if(luckySheetService.updateSysLuckySheet(sysLuckySheet))return RestResponse.success();
        return RestResponse.failure("修改失败");
    }

    @ApiOperation(value = "getByID办公数据")
    @XudenSysLog("getByID办公数据")
    @GetMapping("getById")
    public RestResponse getById(@RequestParam(value = "id")Long id){
        return RestResponse.success().setData(luckySheetService.getByID(id));
    }


    /**
     * 功能描述：删除办公信息（单条记录）
     * @param id
     * @return
     */
    @ApiOperation(value = "删除办公信息（单条记录）")
    @XudenSysLog("删除办公信息（单条记录）")
    @PreAuthorize(hasPermi = "sys:luckySheet:delete")
    @PostMapping("delete")
    public RestResponse delete(@RequestParam(value = "id")Long id){
        luckySheetService.deleteById(id);
        return RestResponse.success();
    }


    /**
     * 功能描述：批量删除办公信息（批量删除）
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除办公信息（批量删除）")
    @XudenSysLog("批量删除办公信息（批量删除）")
    @PreAuthorize(hasPermi = "sys:luckySheet:delete")
    @PostMapping("deletes")
    public RestResponse deletes(@RequestParam("ids[]") List<Long> ids){
        luckySheetService.deleteBatchIds(ids);
        return RestResponse.success();
    }

}
